<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
<meta name="renderer" content="webkit"/>
<meta name="force-rendering" content="webkit"/>
<title></title>
<#include "../style.ftl" />
<script type="text/javascript">

</script>
</head>
<body>
<div class="headerbox">
  <div class="header">
    <div class="headerL">
      <a onclick="javascript:history.back(-1)" class="goback"><img src="${staticPath}front/images/goback.png" /></a>
    </div>
    <div class="headerC">
      <p>购物车(${cartList?size})</p>
    </div>
    <div class="headerR"></div>
  </div>
</div>
<div class="clear"></div>
<div class="hbox"></div>
<div class="kbox"></div>
<div class="gwcbox">
  <div class="gwcbox_1">
    <div class="clear"></div>
    <div class="gwc1_2">
      <#list cartList as cart>
      <div class="gwcone">
        <div class="go1">
          <div class="gwccheck" data-id="${cart.cartItemId}" data-qty="${cart.qty}" data-price="${cart.sellPrice}"></div>
        </div>
        <div class="go2"><a href="${basePath}product/${cart.productId}"><img src="${imagesPath}${cart.logo!}" /></a></div>
        <div class="go3">
          <div class="go3_1">
            <a href="xq.html"><p class="p1">${cart.productName!}</p></a>
          </div>
          <div class="go3_2">
            <p class="p3">${cart.skuName!}</p>
            <p class="p4">￥${cart.sellPrice!}</p>
          </div>
          <div class="go3_3">
            <div>×${cart.qty!}</div>
            <div class="del"><img src="${staticPath}front/images/del.png" onclick="delCart(${cart.cartItemId})"/></div>
          </div>
        </div>
      </div>
      </#list>
    </div>
  </div>
</div>
<div class="fbox1"></div>
<div class="hejiBox">
  <div class="heji">
    <div class="heji_3"><p>合计：<span id="toSettleAmount">￥0</span></p></div>
    <div class="heji_5">
      <a href="javascript:toSettle()" id="toSettle">去结算(0)</a>
    </div>
  </div>
</div>
<#assign isCart=true>
<#include "../footer.ftl">
<script>
  var toSettleCnt = 0;
  var toSettleAmount = 0;
  var ids=[];
  $(document).ready(function () {
    $('.gwccheck').click(function(){
      var tmp = $(this).data('qty')*$(this).data('price');
      if($(this).attr("class")=="gwccheck on"){
        $(this).removeClass('on');
        toSettleCnt = toSettleCnt - 1;
        toSettleAmount = toSettleAmount - tmp;
        ids = ids.filter(item=>item!=$(this).data('id'));
      }else{
        $(this).addClass('on');
        toSettleCnt = toSettleCnt + 1;
        toSettleAmount = toSettleAmount + tmp;
        ids.push($(this).data('id'));
      }
      console.info(ids)
      $('#toSettle').html('去结算('+toSettleCnt+')');
      $('#toSettleAmount').html('￥'+toSettleAmount);
    })
    $('#toSettle').html('去结算('+toSettleCnt+')');
    $('#toSettleAmount').html('￥'+toSettleAmount);
  })
  function delCart(id){
    jQuery.post("${basePath}home/cartItem/del", {'cartItemId':id},function(result){
      if(result.success){
        location.href="${basePath}home/cart";
      }else {
        alert(result.msg);
      }
    });
  }
  function toSettle(){
    if(ids.length==0){
      return;
    }
    var itemIds = ids.join(',');
    document.location.href='${basePath}home/settle/cart?cartIds='+itemIds;
  }
</script>
</body>
</html>
